package ${packageBase}.service;

import ${packageBase}.model.${tableBean.tableNameCapitalized};
import ${packageBase}.dao.${tableBean.tableNameCapitalized}${classPrefix}DAO;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("${tableBean.tableNameNoDash}${classPrefix}Service")
public class ${tableBean.tableNameCapitalized}${classPrefix}ServiceImpl implements ${tableBean.tableNameCapitalized}${classPrefix}Service {
    @Resource
    private ${tableBean.tableNameCapitalized}${classPrefix}DAO ${tableBean.tableNameNoDash}${classPrefix}DAO;

    @Override
    public int save(${tableBean.tableNameCapitalized} ${tableBean.tableNameNoDash}) {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.insertSelective(${tableBean.tableNameNoDash});
    }

    @Override
    public int saveAndGetId(${tableBean.tableNameCapitalized} ${tableBean.tableNameNoDash}) {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.insertSelectiveAndGetId(${tableBean.tableNameNoDash});
    }

    @Override
    public int update(${tableBean.tableNameCapitalized} ${tableBean.tableNameNoDash}) {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.updateByPrimaryKeySelective(${tableBean.tableNameNoDash});
    }

    @Override
    public int saveOrUpdate(${tableBean.tableNameCapitalized} ${tableBean.tableNameNoDash}) {
        if (null == ${tableBean.tableNameNoDash}.getId() || 0 == ${tableBean.tableNameNoDash}.getId()) {
            return save(${tableBean.tableNameNoDash});
        } else {
            return update(${tableBean.tableNameNoDash});
        }
    }

    @Override
    public ${tableBean.tableNameCapitalized} get(Integer id) {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.selectByPrimaryKey(id);
    }

    @Override
    public List<${tableBean.tableNameCapitalized}> getAll() {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.selectAll();
    }

    @Override
    public int delete(Integer id) {
        return ${tableBean.tableNameNoDash}${classPrefix}DAO.deleteByPrimaryKey(id);
    }
}
